<template>
  <div>
    <a-input style="width: 50%; margin-right: 20px;" @change="onChange" :placeholder="i18n('predicate.regex','正则表达式')" v-model="args.regexp"></a-input>
    <a-input style="width: 40%;" :placeholder="i18n('filterList.replaceWith','替换为')" @change="onChange" v-model="args.replacement"></a-input>
  </div>
</template>

<script>
  export default {
    name: "RewritePathEdit",
    props: ["value"],
    data() {
      return {
        args: {}
      }
    },
    created() {
      this.init();
    },
    methods: {
      i18n(name,text,key){
          return this.$ti18(name,text,"SysRouting",key);
      },
      init() {
        if (this.value.filterArgs == "") {
          this.args = {
            regexp: "",
            replacement: ""
          };
        } else {
          this.args = {
            regexp: JSON.parse(this.value.filterArgs).regexp,
            replacement: JSON.parse(this.value.filterArgs).replacement
          };
        }
      },
      onChange(){
        var obj={
          _genkey_0:this.args.regexp,
          _genkey_1:this.args.replacement
        };
        this.value.filterArgs=JSON.stringify(obj);
      }
    },
    watch: {
      "value.filterName": function (val, oldVal) {
        this.init();
      }
    }
  }
</script>

<style scoped>

</style>